/**
 * 
 */
package src.knock;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @author javaOne
 *
 */
public class KKMultiServerThread extends Thread {

	/**
	 * 
	 */

    private Socket socket = null;
	static Map parametrosX = new HashMap();

	public static PrintWriter outX = null;
	public static BufferedReader inX = null;

    String inputLineX, outputLineX;
    String cadenaEnviar = "";
    
	public KKMultiServerThread() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param target
	 */
	public KKMultiServerThread(Runnable target) {
		super(target);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param name
	 */
	public KKMultiServerThread(String name) {
		super(name);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param group
	 * @param target
	 */
	public KKMultiServerThread(ThreadGroup group, Runnable target) {
		super(group, target);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param group
	 * @param name
	 */
	public KKMultiServerThread(ThreadGroup group, String name) {
		super(group, name);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param target
	 * @param name
	 */
	public KKMultiServerThread(Runnable target, String name) {
		super(target, name);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param group
	 * @param target
	 * @param name
	 */
	public KKMultiServerThread(ThreadGroup group, Runnable target, String name) {
		super(group, target, name);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param group
	 * @param target
	 * @param name
	 * @param stackSize
	 */
	public KKMultiServerThread(ThreadGroup group, Runnable target, String name,
			long stackSize) {
		super(group, target, name, stackSize);
		// TODO Auto-generated constructor stub
	}

    public KKMultiServerThread(Socket socket) {
    	super("KKMultiServerThread");
    	this.socket = socket;
    	System.out.println("getHostAddress: " + this.socket.getInetAddress().getHostAddress());
    }

    public KKMultiServerThread(Socket socket, Map parametros) {
    	super("KKMultiServerThread");
    	this.socket = socket;
    	this.parametrosX = parametros;
    	System.out.println("getHostAddress: " + this.socket.getInetAddress().getHostAddress());
    }
    
    public void run(){
    	try {
    		cadenaEnviar = "";
    	    outX = new PrintWriter(socket.getOutputStream(), true);
    	    inX = new BufferedReader( new InputStreamReader( socket.getInputStream()));

	    	for(int i = 1; i <= parametrosX.size() ; i++){
	    		cadenaEnviar = null;
	    		cadenaEnviar = (String)parametrosX.get("LINEA" + i);
	    		outputLineX = cadenaEnviar;
	            outX.println(outputLineX);
	            //while ((inputLine = in.readLine()) != null) {
	    	    	//outputLine = kkp.processInput(inputLine);
	            //     outputLine = kkp.procederEntrada(inputLine);
	            //     out.println(outputLine);
	            //     if (outputLine.equals("Bye."))
	            //        break;
	            //}
	    	}
	    	outputLineX = ("101");
            outX.println(outputLineX);
		} catch (Exception e) {
			// TODO: handle exception
		}
    }
    /*
    public void run() {

    	try {
    	    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    	    BufferedReader in = new BufferedReader( new InputStreamReader( socket.getInputStream()));

    	    String inputLine, outputLine;
    	    KnockKnockProtocol kkp = new KnockKnockProtocol();
            //outputLine = kkp.processInput(null);
            outputLine = kkp.procederEntrada(null);
    	    out.println(outputLine);

    	    while ((inputLine = in.readLine()) != null) {
    	    	//outputLine = kkp.processInput(inputLine);
    	    	outputLine = kkp.procederEntrada(inputLine);
    	    	out.println(outputLine);
    	    	if (outputLine.equals("Bye"))
    	    		break;
    	    }
    	    out.close();
    	    in.close();
    	    socket.close();

    	} catch (IOException e) {
    	    e.printStackTrace();
    	}
	}*/
}
